import enterDepotList from "../../api/aftersale-enter-depot";
import dateOptions from "@/utils/date"; //引入date的渲染


let brand = {
    data(){
        return{
            dateOptions,
            tableData: [],//数据信息
            total: 0,//总条数
            searchParams: {
                currentPage: 1,
                pageSize: 5
            },
            formData: {
                inType:0,
                inStatus:0,
            },//新增表单信息
            inTypeList:[],//售后入库订单类型
            inStatusList:[],//售后入库订单状态
            batchIds: [],//批量删除  判断选中是否修改 和删除
            dialogVisible: false,//新增窗口默认不开
        }
    },
    methods:{
        /**
         * 查询所有
         */
        async searchPage() {
            console.log(this.searchParams);
            let response = await enterDepotList.findPage(this.searchParams);
            this.total = response.total;//总行数赋值
            this.tableData = response.data;//数据信息赋值
        },
        //下拉框
        async queryDic() {
            let result = await enterDepotList.queryAllDic();
            this.inTypeList= result[3];
            this.inStatusList= result[1];
        },
        //时间框 选择时间
        chooseTime() {
            this.searchParams.startTime = this.dateOptions.startDate[0];
            this.searchParams.endTime = this.dateOptions.startDate[1];
        },
        //点击重置
        resetForm() {
            //重置第一页信息
            this.searchParams = {currentPage: 1, pageSize: 5};
            this.dateOptions.startDate = '';//时间选择框清空
        },
        currentPageChange(currentPageIndex) {
            console.log(currentPageIndex);
            this.searchParams.currentPage = currentPageIndex;
            this.searchPage();
        },
        //checkbox勾选改变
        selectChange(val) {
            console.log(val)
            /**
             * 复选框选择修改 进行id赋值
             */
            if (val.length == 1) {
                //id赋值
                this.formData.id = val[0].id;
            } else {
                this.formData.id = "";
            }


            //勾选二个的时候修改失效  删除有效
            this.batchIds = val.map(item => item.id)
        },
        //删除单个
        async deleteById() {
            await enterDepotList.delById(this.formData.id);
            this.searchPage();
        },
        //根据id查询
        async findById(){

            this.formData = await enterDepotList.findById(this.formData.id);

            if (this.formData.inType==1){
                this.formData.inType="返厂维修入库";
            } else if(this.formData.inType==2){
                this.formData.inType="退换货入库";
            }
            if (this.formData.inStatus==0) {
                this.formData.inStatus = "待入库";
            }else if (this.formData.inStatus == 1) {
                this.formData.inStatus = "已入库";
            }
        },
        /**
         * 添加和修改
         */
        async addOrEdit(){
            if (this.formData.id){
                //修改
                await this.update();
            }else {
                //新增加
                await this.save();
            }
            //刷新
            this.searchPage();
        },
        //修改
        async update(){
            await enterDepotList.updateEntity(this.formData);
            this.searchPage();
        },
        //新增
        async save(){
            await enterDepotList.addEntity(this.formData);
            this.searchPage();
        },
        /**
         * 批量删除
         */
        async batchDeleteByIds() {
            await enterDepotList.batchDelete(this.batchIds);
            this.searchPage();
        },
        /**
         * 显示批量删除框
         */
        showBatchDeleteDialog() {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.batchDeleteByIds();
            })
        },
    },
    created(){
        this.searchPage();
        this.queryDic();
    }
};

export default brand;